#include "io.h"
#include <string.h>
#include <assert.h>
#include <malloc.h>

sFile* statFile(const char* name)
{
    sFile* file=(sFile*)calloc(1,sizeof(sFile));
    file->info=(struct stat*)calloc(1,sizeof(struct stat));
    if(stat(name,file->info)!=0)
    {
        free(file);
        return NULL;
    }
    else
    {
        file->name=(char*)calloc(strlen(name),sizeof(char));
        strcpy(file->name,name);
        return file;
    }
}

int readFile(sFile* file)
{
    buffer_t* buffer;
    assert(file!=NULL);

    if((file->fd=fopen(file->name,"r"))<0)
    {
        return 1;
    }
    else
    {
        file->buffer=mem_newBuffer();
        buffer=file->buffer;
        int tmp;
        int i=0;
        for(i=0;(tmp=fgetc(file->fd))!=EOF;i++)
        {
            mem_addChar(buffer,tmp,i);
        }
        fclose(file->fd);
    }
    return 0;
}


int writeFile(sFile* sf)
{
    printf("No Write File Functionality At This Time\n");
    return 0;
}



